﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;
using System.ComponentModel;
using HMS.ClassLibrary;

namespace HMS
{
    /// <summary>
    /// Interaction logic for ProgressWindow.xaml
    /// </summary>
    public partial class ProgressWindow : Window
    {
        private BackgroundTask Task;
       
        public ProgressWindow()
        {
            InitializeComponent();
            
        }
        public ProgressWindow(DoWorkEventHandler doWorkEvent)
        {
            InitializeComponent();
            try
            {
                this.Task = new BackgroundTask();
                this.Task.DoWork += this.DoWork;
                this.Task.DoWork += doWorkEvent;
                this.Task.RunWorkerCompleted += RunWorkerCompleted;
                this.Task.RunWorkerAsync();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, Properties.Resources.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Error);
            
            }
        }
        public ProgressWindow(DoWorkEventHandler doWorkEvent,RunWorkerCompletedEventHandler workCompletedEvent)
        {
            InitializeComponent();
            try
            {
                this.Task = new BackgroundTask();
                this.Task.DoWork += this.DoWork;
                this.Task.DoWork += doWorkEvent;
                this.Task.RunWorkerCompleted += workCompletedEvent;
                this.Task.RunWorkerCompleted +=this.RunWorkerCompleted;
                this.Task.RunWorkerAsync();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, Properties.Resources.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Error);
      
            }
        }
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            //intentionaly added delay to show the progrees animation
            for (int i = 0; i < 10; i++)
            {
                Thread.Sleep(50);
            }
     

        }

        [STAThread]
        private void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.Close();
        }


       
    }
}
